package com.sn.campus.serviceImpl;


import com.sn.campus.entity.Operat;
import com.sn.campus.dao.OperationDao;
import com.sn.campus.model.OperationException;
import com.sn.campus.service.OperationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;


/**
 * @ProjectName: springboot_socket
 * @Package: com.sn.socket.serviceImpl
 * @ClassName: ${CLASS_NAME}
 * @Author: xiahuihui
 * @Description: ${description}
 * @Date: 2020/5/12 0012 10:39
 * @Version: 1.0
 */

@Service
public class OperationServiceImpl implements OperationService {

    @Resource
    private OperationDao operationDao;


    private static final Logger logger = LoggerFactory.getLogger(OperationServiceImpl.class);

//    private SockServer sockServer = SockServer.getInstance();


    public void acceptAlarm() throws OperationException {

    }

    @Override
    public void timelyTask(Operat operat) {

        //                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //                    String createTime = df.format(new Date());
        //                    operationMapping.insertRealTime(deviceId,operat.getCommand(),operat.getFrequency(),operat.getTime(),createTime);
        //            try {
        //
        //                nettyTcpClient.sendMsg(message);
        //                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //                String createTime = df.format(new Date());
        //                operationMapping.insertRealTime(deviceId,operat.getCommand(),operat.getFrequency(),operat.getTime(),createTime);
        //            } catch (Exception e) {
        //                e.printStackTrace();
        //            }
//        for (String deviceId : operat.getDeviceId()) {
//            String message = operat.getCommand() + "#" + operat.getFrequency() + "#" + operat.getTime() + "#" + "A";
//            logger.info(deviceId, message);
//            ChannelId channelId = NettyServerHandler.getDeviceMap().get(deviceId);
//            NettyServerHandler nettyServerHandler = new NettyServerHandler();
//            if (channelId != null) {
//                try {
//                    nettyServerHandler.channelWrite(NettyServerHandler.getDeviceMap().get(deviceId), message);
//                } catch (Exception e) {
//                    logger.error("发送即时任务异常！！！！");
//                    throw new OperationException(ResultEnum.RESULT_SEND_MESSAGE_ERROR);
//                }
//            } else {
//                logger.error("该设备未连接，找不到该设备！！！！");
//                throw new OperationException(ResultEnum.RESULT_NOT_FOUND_DEVICE_ERROR);
//            }
//        }

    }

    //---------------------------首页数据-----------------------------
    @Override
    public List<HashMap<String,Object>> getIndexCommunities() {
        return operationDao.getIndexCommunities();
    }
    @Override
    public List<HashMap<String,Object>> getIndexTop5() {
        return operationDao.getIndexTop5();
    }
    @Override
    public List<HashMap<String,Object>> getIndextotalstat() {
        return operationDao.getIndextotalstat();
    }
    @Override
    public List<HashMap<String,Object>> getIndexTop10() {
        return operationDao.getIndexTop10();
    }
    @Override
    public List<HashMap<String,Object>> getIndexDeviceStat() {
        return operationDao.getIndexDeviceStat();
    }
    @Override
    public List<HashMap<String,Object>> getIndexClockStat() {
        return operationDao.getIndexClockStat();
    }
    @Override
    public List<HashMap<String,Object>> getIndexSosStat() {
        return operationDao.getIndexSosStat();
    }

    //----------------------单个学校数据-----------------------------------
    @Override
    public List<HashMap<String,Object>> getSchoolAttends(String communityno_) {
        return operationDao.getSchoolAttends(communityno_);
    }
    @Override
    public List<HashMap<String,Object>> getSchoolTemps(String communityno_) {
        return operationDao.getSchoolTemps(communityno_);
    }
    @Override
    public List<HashMap<String,Object>> getSchoolMonitorVideo(String communityno_) {
        return operationDao.getSchoolMonitorVideo(communityno_);
    }
    @Override
    public List<HashMap<String,Object>> getSchoolSosVideo(String communityno_) {
        return operationDao.getSchoolSosVideo(communityno_);
    }
}
